﻿using InterfaceComponents;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Sirian;
using Microsoft.Xna.Framework.Input;

namespace SirianTestEnvironment
{
    
    
    /// <summary>
    ///Dies ist eine Testklasse für "ButtonTest" und soll
    ///alle ButtonTest Komponententests enthalten.
    ///</summary>
    [TestClass()]
    public class ButtonTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Ruft den Testkontext auf, der Informationen
        ///über und Funktionalität für den aktuellen Testlauf bietet, oder legt diesen fest.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Zusätzliche Testattribute
        // 
        //Sie können beim Verfassen Ihrer Tests die folgenden zusätzlichen Attribute verwenden:
        //
        //Mit ClassInitialize führen Sie Code aus, bevor Sie den ersten Test in der Klasse ausführen.
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Mit ClassCleanup führen Sie Code aus, nachdem alle Tests in einer Klasse ausgeführt wurden.
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Mit TestInitialize können Sie vor jedem einzelnen Test Code ausführen.
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Mit TestCleanup können Sie nach jedem einzelnen Test Code ausführen.
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///Ein Test für "Update"
        ///</summary>
        [TestMethod()]
        public void UpdateTest()
        {
            Rectangle border = new Rectangle(0,0,10,10);
            string name = string.Empty;
            Vector2 position = new Vector2();
            SpriteBatch spriteBatch = null;
            SpriteFont spriteFont = null;
            SirianGame.Modes next = new SirianGame.Modes();
            SirianGame.Modes parent = new SirianGame.Modes();
            PrivateObject param0 = new PrivateObject(new Button(border, name, position, spriteBatch, spriteFont, next, parent));
            Button_Accessor target = new Button_Accessor(param0);
            KeyboardState keyboard = new KeyboardState();
            KeyboardState oldKeyboard = new KeyboardState(new Keys[] { Keys.Enter });
            MouseState mouse = new MouseState(1, 1, 0, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released);
            MouseState oldMouse = new MouseState(1, 1, 0, ButtonState.Pressed, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released);
            bool selected = true;
            Assert.IsTrue(selected && target.KeyPressed(keyboard, oldKeyboard, Keys.Enter));
            Assert.IsTrue(oldMouse.LeftButton == ButtonState.Pressed && mouse.LeftButton == ButtonState.Released && border.Intersects(new Rectangle(mouse.X, mouse.Y, 1, 1)));
        }

        /// <summary>
        ///Ein Test für "KeyPressed"
        ///</summary>
        [TestMethod()]
        [DeploymentItem("SirianGame.exe")]
        public void KeyPressedTest()
        {
            PrivateObject param0 = new PrivateObject(new Button(new Rectangle(), "", Vector2.Zero, null, null, SirianGame.Modes.Achievement, SirianGame.Modes.Achievement));
            Button_Accessor target = new Button_Accessor(param0);
            KeyboardState keyboard = new KeyboardState();
            KeyboardState oldKeyboard = new KeyboardState(new Keys[] { Keys.Enter });
            Keys key = Keys.Enter;
            bool expected = true;
            bool actual;
            actual = target.KeyPressed(keyboard, oldKeyboard, key);
            Assert.AreEqual(expected, actual);
        }
    }
}
